﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace TotalApplication.Core
{
    public partial class LoginViewModel : BaseViewModel
    {
        #region public properties

        [ObservableProperty]
        private string? _email;

        [ObservableProperty]
        private bool _isUpdating;

        #endregion

        #region private properties


        #endregion

        #region commands

        [RelayCommand]
        private async Task Login(object parameter)
        {
            await RunCommand(() => IsUpdating, async () =>
            {
                await Task.Delay(1000); // Simulate a login delay

                // OK successfully logged in... now get users information
                // TODO: Ask server for user information

                // TODO: Remove this with real login information pulled from our database in future
                IoC.SettingMenu.Name = new TextEntryDesignModel() { OriginalText = "Tian_ZJ" };
                IoC.SettingMenu.Username = new TextEntryDesignModel() { Label = "Username", OriginalText = "TZJlll" };
                IoC.SettingMenu.Password = new PasswordEntryDesignModel();
                IoC.SettingMenu.Email = new TextEntryDesignModel() { Label = "Email", OriginalText = "a534286562@163.com" };

                // Let's go to chat page
                IoC.Application.GoToPage(ApplicationPage.Chat);

                //var email = Email;
                //var pass = ((IHavePassword)parameter).Password.Unsecure();

                //// IMPORTANT: Never store the unsecure password in varible like this
            });

        }


        [RelayCommand]
        private async Task Register(object parameter)
        {
            //IoC.Application.SideMenuVisible ^= true;
            //return;

            // Update page inforrmation to change page
            IoC.Application.GoToPage(ApplicationPage.Register);

            await Task.Delay(1);
        }

        #endregion


    }
}
